﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

public partial class PersonInfo_HelpMessageEdit : BasePage
{
    private Access access = new Access();
    HelpMessageBO mbo = new HelpMessageBO();
    private static int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

            if (GetQeuryString("para") == "update")
            {
                string id = GetQeuryString("id");
                HelpMessage m = mbo.GetModel(int.Parse(id));
                InitData(m);
            }
            else if (GetQeuryString("para") == "add")
            {
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        HelpMessage m = GetEntity();
        if (GetQeuryString("para") == "add")
        {

            mbo.Add(m);
            AlertAndCloseAndReloadParendDataGrid("保存成功！", "grid");

        }
        else if (GetQeuryString("para") == "update")
        {
            mbo.Update(m);
            AlertAndCloseAndReloadParendDataGrid("保存成功！", "grid");
        }
    }

    #region 私有方法
    private HelpMessage GetEntity()
    {
        HelpMessage m = new HelpMessage();
        if (GetQeuryString("para") == "update")
        {
            string id = GetQeuryString("id");
            m = mbo.GetModel(int.Parse(id));
        }
        m.Content = content1.InnerText;
        m.Time = DateTime.Parse(txtTime.Text);
        m.Title = txtTitle.Text;
        m.JJ = txtJJ.Text;
        return m;
    }
    private void InitData(HelpMessage m)
    {
        txtTime.Text = m.Time.ToString();
        txtTitle.Text = m.Title;
        content1.InnerText = m.Content;
        txtJJ.Text = m.JJ;
        id = m.Id;
    }

    #endregion
}